package com.zhenxiang.timer;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

/**
 * @Author : James
 * @Create : 2022-01-05-18:01
 * @Description :  自定义定时器 调度任务
 */
public class CustomTimer extends TimerTask {


    /**
     *  执行调度的任务
     */
    @Override
    public void run() {
    runTask();
    }

    public void runTask(){
        System.out.println("运行了任务+"+ LocalDateTime.now());
    }

    public static void main(String[] args) {
        CustomTimer customTimer = new CustomTimer();
        Timer timer = new Timer();
        timer.schedule(customTimer, new Date(), 2000);
    }


}
